n,k=map(int,input().split())

a=[i for i in range(1,n+1)]

count=n
number=0
i=0
while True:
    number+=1
    if number%10==k or number%k==0:
        a.pop(i)
        count-=1
        if count==1:
            print(a[0])
            exit(0)
        if i==len(a):
            i=0
        continue
    else:
        i+=1
        if i==len(a):
            i=0

